#include "key.h"

int key_Scan()
{
	if(key01 == 0)
	{
		delay1ms(20);
		if(key01 == 0) return 1;
	}
	
	
	if(key02 == 0)
	{
		delay1ms(20);
		if(key02 == 0) return 2;
	}
	
	
	if(key03 == 0)
	{
		delay1ms(20);
		if(key03 == 0) return 3;
	}
	
	
	if(key04 == 0)
	{
		delay1ms(20);
		if(key04 == 0) return 4;
	}
	return 0;
}

int key1_Scan(){
	int key = 16;
	P3 = 0xF0;
	if(P3 != 0xF0){
		delay1ms(20);
		if(P3 != 0xF0){
			if(P3 == 0xE0) key = 0;
			if(P3 == 0xD0) key = 1;
			if(P3 == 0xB0) key = 2;
			if(P3 == 0x70) key = 3;
			
			P3 = 0x0F;
			
			if(P3 == 0x0E) key += 0;
			if(P3 == 0x0D) key += 4;
			if(P3 == 0x0B) key += 8;
			if(P3 == 0x07) key += 12;
		}
		while(P3 != 0x0F);
	}
	return key;
}
